import {Engine, Scene} from "babylonjs";
import * as BABYLON from 'babylonjs';
import 'babylonjs-loaders';

export default class BabylonApp {
    engine: Engine;
    scene: Scene;

    constructor(private canvas: HTMLCanvasElement) {
        this.engine = new Engine(this.canvas, true);
        this.scene = new Scene(this.engine);
        this.scene.createDefaultCamera(true, true, true)
        this.scene.createDefaultLight();
        this.scene.createDefaultEnvironment();
        this.init();

        this.engine.runRenderLoop(() => {
            this.engine.resize();
            this.scene.render();
        })
    }

    init() {
        const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', {
            diameter: 0.1,
        })
        sphere.position.x = 0.0;
        sphere.position.y = 0.05;
        // const cylinder = BABYLON.MeshBuilder.CreateCylinder('cylinder', {
        //     diameter: 0.1,
        //     height: 0.1,
        // })
        // cylinder.position.x = -0.2;
        // cylinder.position.y = 0.05;
        // BABYLON.SceneLoader.Append("./", "scene.babylon", this.scene, function (scene) {
        //     // scene.createDefaultCameraOrLight(true, true, true);
        //     // scene.activeCamera.alpha+=Math.PI;
        // })
        BABYLON.SceneLoader.ImportMeshAsync('', 'E:\\repos\\gravity\\gravity\\play\\icon\\babylon\\', 'scene.glb', this.scene).then(pirateFortImport => {
            // pirateFortImport.meshes[0].name = 'pirateFort'
            // scene.getMeshByName('sea').material.needDepthPrePass = true
            // scene.getLightByName('Sun').intensity = 12
        });

    }
}